package com.hadoop.project.entity.constant;

import com.hadoop.project.component.RedisComponent;
import com.hadoop.project.entity.hbase.ProcessRes;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Alexmaodali
 * @usage:redis存储相关常量及方法
 */
@Component("xComponent")
public class RedisComplexConstant {

    @Resource
    private RedisComponent redisComponent;

    public static final String Key_Tab_Rank_List = "hadoopcmp:data:tabranklist:";
    public static final String Key_Video_Rank_List = "hadoopcmp:data:videoranklist:";
    public static final String Key_User_Flavor_List = "hadoopcmp:data:userflavorlist:";

    /**
     * 存入hbase数据到redis
     *
     * @param processRes
     */
    public void saveData2Redis(ProcessRes processRes) {
        redisComponent.setTabRankList(processRes.getTabRankList());
        redisComponent.setVideoRankList(processRes.getVideoRankList());
        redisComponent.setUserFlavorList(processRes.getUserFlavorList());
    }

    /**
     * 从redis获取hbase数据
     *
     * @return
     */
    public ProcessRes getDataFromRedis() {
        return ProcessRes.builder().tabRankList(redisComponent.getTabRankList()).videoRankList(redisComponent.getVideoRankList()).userFlavorList(redisComponent.getUserFlavorList()).build();
    }
}
